# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ocaml-otr
_pkgname=otr
pkgver=0.3.10
pkgrel=2
pkgdesc="Off the record implementation purely in OCaml"
url="https://github.com/hannesm/ocaml-otr"
arch="all !riscv64 !loongarch64" # ocaml
license="BSD-2-Clause"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-astring-dev
	ocaml-base64-dev
	ocaml-cstruct-dev
	ocaml-mirage-crypto-dev
	ocaml-sexplib0-dev
	"
makedepends="$depends_dev dune ocaml"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.bz2::https://github.com/hannesm/ocaml-otr/releases/download/v$pkgver/otr-v$pkgver.tbz"
builddir="$srcdir/$_pkgname-v$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
24eee63e54c29e27d90718fe764178d5ee8b9fa599c7ca25b042e57b2442501089c51f11656315949f60e0362f86f743597c74dd968c4d3472e18c4def5179ba  ocaml-otr-0.3.10.tar.bz2
"
